package com.shujia.mysql;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;

/**
 * @Description: MYSQLJDBC4 更新 修改数据
 * @Author: 王火火
 * @Date: 2019/9/6 15:00
 */
public class MYSQLJDBC4 {
    //创建常量
    static final String DRIVER = "com.mysql.jdbc.Driver";//驱动
    static final String URL = "jdbc:mysql://master:3306/shujia";//路劲
    static final String USERNAME = "root";//用户名
    static final String PASSWORD = "123456";//密码

    public static void main(String[] args) throws Exception {
        //加载驱动
        Class.forName(DRIVER);
        //获取连接
        Connection conn = DriverManager.getConnection(URL, USERNAME, PASSWORD);
        String sql = "UPDATE emp set ename=?,job=? WHERE empno=?";
        //获取执行器
        PreparedStatement ps = conn.prepareStatement(sql);
        //ename="student",job="BOSS" empno=20
        ps.setString(1,"student");
        ps.setString(2,"BOSS");
        ps.setInt(3,20);
        int i = ps.executeUpdate();
        if(i==1){
            System.out.println("修改成功");
        }
        ps.close();
        conn.close();
    }
}
